/**
 * 
 */
package kevin.study.zephyr.domain.dao.soda;

import java.util.ArrayList;
import java.util.Collection;

import kevin.study.zephyr.domain.soda.Constraint;
import kevin.study.zephyr.domain.soda.Constraints;


/**
 * @author Kevin.Huang
 * @createtime 2007-9-30
 */
public class ZConstraints implements Constraints {

	private Collection< ZConstraint > constraints;

	protected ZConstraints(Collection< ZConstraint > constraints) {
		if (constraints != null) {
			this.constraints = constraints;
		} else {
			this.constraints = new ArrayList< ZConstraint >();
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraints#toArray()
	 */
	public Constraint[] toArray() {
		Constraint[] c = new Constraint[this.constraints.size()];
		return this.constraints.toArray(c);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#and(kevin.study.zephyr.domain.soda.Constraint)
	 */
	public Constraint and(Constraint with) {
		for (Constraint c : constraints) {
			c.and(with);
		}
		return this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#contains()
	 */
	public Constraint contains() {
		for (Constraint c : constraints) {
			c.contains();
		}
		return this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#equal()
	 */
	public Constraint equal() {
		for (Constraint c : constraints) {
			c.equal();
		}
		return this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#getObject()
	 */
	public Object getObject() {
		Collection< Object > objs = new ArrayList< Object >();
		for (Constraint c : constraints) {
			objs.add(c.getObject());
		}
		return objs;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#greater()
	 */
	public Constraint greater() {
		for (Constraint c : constraints) {
			c.greater();
		}
		return this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#like()
	 */
	public Constraint like() {
		for (Constraint c : constraints) {
			c.like();
		}
		return this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#not()
	 */
	public Constraint not() {
		for (Constraint c : constraints) {
			c.not();
		}
		return this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#or(kevin.study.zephyr.domain.soda.Constraint)
	 */
	public Constraint or(Constraint with) {
		for (Constraint c : constraints) {
			c.or(with);
		}
		return this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see kevin.study.zephyr.domain.soda.Constraint#smaller()
	 */
	public Constraint smaller() {
		for (Constraint c : constraints) {
			c.smaller();
		}
		return this;
	}

	public Constraint endsWith(boolean caseSensitive) {
		for (Constraint c : constraints) {
			c.endsWith(caseSensitive);
		}
		return this;
	}

	public Constraint startsWith(boolean caseSensitive) {
		for (Constraint c : constraints) {
			c.startsWith(caseSensitive);
		}
		return this;
	}

}
